﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FactortMethod;
using AbstractFactory;
using BuilderPattern;
using DesignPatternTest.Adapter;
using DesignPatternTest.BridgePattern;
using DesignPatternTest.DecoratorPattern;

namespace DesignPatternTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //DecoratorPatternTest
            DecoratorPatternTest.RunTest(); 

            //BridgePatternTest
            BridgePatternTest.Run();

            //Test Adapter Pattern 
            TestAdapterPattern();

            //test factory method
            TestFactoryMethod();

            //Test Abstract Factory
            TestAbstractFactory();

            //TestBuilder()
            TestBuilder();
        }


        /// <summary>
        /// TestAdapter
        /// </summary>
        static void TestAdapterPattern() 
        {
            // Create adapter and place a request 
            Target target = new DesignPatternTest.Adapter.Adapter();
            target.Request();

            // Wait for user 
            Console.Read();
        }

        /// <summary>
        /// TestBuilder
        /// </summary>
        static void TestBuilder()
        {
            VehicleBuilder builder;

            // Create shop with vehicle builders
            Shop shop = new Shop();

            // Construct and display vehicles
            builder = new ScooterBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new CarBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new MotorCycleBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            // Wait for user
            Console.ReadKey();
        }

        /// <summary>
        /// cosume factory method pattern
        /// </summary>
        static void TestFactoryMethod() 
        {
            IFruitFactory factory = new FruitFactory();
            IFruit fruit;

            var reslt = String.Empty;

            fruit = factory.CreateApple();
            reslt = fruit.GetDescription();
            Console.WriteLine(reslt);

            reslt = String.Empty;
            fruit = factory.CreateOrange();
            reslt = fruit.GetDescription();
            Console.WriteLine(reslt);

            Console.Read();
        }

        /// <summary>
        /// TestAbstractFactory
        /// </summary>
        static void TestAbstractFactory() 
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld world = new AnimalWorld(africa);
            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();

            ContinentFactory asia = new AsiaFactory();
            world = new AnimalWorld(asia);
            world.RunFoodChain();

            // Wait for user input
            Console.ReadKey();
        }
    }
}
